package com.hwtx.form.domain.def;

import lombok.Builder;
import lombok.Getter;

import java.util.Locale;

public class GenFormContextHolder {

    private static final ThreadLocal<GenFormInfo> contextHolder = new ThreadLocal<>();

    public static FormDef getFormDef() {
        return contextHolder.get().getFormDef();
    }

    public static void init(GenFormInfo genFormInfo) {
        contextHolder.set(genFormInfo);
    }

    public static GenFormInfo getGenFormInfo() {
        return contextHolder.get();
    }

    public static Long getFormId() {
        return contextHolder.get().getFormId();
    }

    public static String getDomain() {
        return contextHolder.get().getDomain();
    }

    public static String getContextPath() {
        return contextHolder.get().getContextPath();
    }

    public static Locale getLocale() {
        return contextHolder.get().getLocale();
    }

    public static void clear() {
        contextHolder.remove();
    }


    @Builder
    @Getter
    public static class GenFormInfo {
        private Long formId;
        private String domain;
        private FormDef formDef;
        private String contextPath;
        private Locale locale;
    }
}